package com.appspot.ldsdrawingtool.server.services;

import java.util.ArrayList;
import java.util.List;
import com.appspot.ldsdrawingtool.client.services.stubs.UserAccountServiceStub;
import com.google.appengine.api.channel.ChannelService;
import com.google.appengine.api.channel.ChannelServiceFactory;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class UserAccountServiceImpl extends RemoteServiceServlet implements UserAccountServiceStub {
    
    private static final String homePageUrl = "http://ldsdrawingtool.appspot.com";
    public static List<String> channellingUsers = new ArrayList<String>(); 
    
    @Override
    public String createUserChannel(String userID) {
        ChannelService channelService = ChannelServiceFactory.getChannelService();
        String token = channelService.createChannel(userID);
        channellingUsers.add(userID);
        return token;
    }

    @Override
    public String getLoginLogoutUrl() {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        if (user != null) {
            return userService.createLogoutURL(homePageUrl);
        } else {
            return userService.createLoginURL(homePageUrl);
        }
    }
    
}